<!-- $Id: captcha_manage.htm 14868 2008-09-11 09:51:13Z dolphin $ -->
{include file="pageheader.htm"}

<div class="list-div">
<form method="post" action="captcha_manage.php" name="theForm" onsubmit="return validate()" >
<table cellpadding='3' cellspacing='1'>
<tr>
  <th colspan="2">{$lang.captcha_setting}</th>
</tr>
  <tr>
    <td>
      <strong>{$lang.captcha_type}</strong><br />
      {$lang.captcha_type_note}
    </td>
    <td><input type="radio" name="captcha_type" value="1" {$captcha.default} />{$lang.default_type}<input type="radio"  name="captcha_type" value="2" {$captcha.tencent} />{$lang.tencent_type}</td>
  </tr>
<tr>
  <td width="60%" >
  <strong>{$lang.captcha_turn_on}</strong><br />
  {$lang.turn_on_note}<br />
    {if $captcha.default neq ""}
    <img src="../captcha.php?{$rand}" alt="captcha" style="vertical-align: middle;cursor: pointer;" onClick="this.src='../captcha.php?'+Math.random()" />
    {/if}
    {if $captcha.tencent neq ""}
    <div>
      <input type="button" name="codeVerifyButton" id="codeVerifyButton" class="button" onclick="onClickCode()" value="{$lang.captcha_machine_test}" style="width: 20%;margin-bottom: 16px;height:40px;">
      <input type="button" id="codePassButton" disabled="disabled" style="background-color: green;color: white;width: 20%;margin-bottom: 16px;height:40px" value="{$lang.captcha_machine_test_pass}"  >
      <input type="hidden" id="codeVerifyTicket" name="codeVerifyTicket" value="">
      <input type="hidden" id="codeVerifyRandstr" name="codeVerifyRandstr" value="">
      <input type="hidden" id="codeVerifyAppid" name="codeVerifyRandstr" value="{$captcha.captcha_app_id}">
      <input type="hidden" id="codeVerifyFlag" name="codeVerifyFlag" value="">
      <br>
      <span id="captcha_machine_test_fail" style="color: red">
        {$lang.captcha_machine_test_fail}
      </span>

    <div/>
    <a href="tencent_captcha.php?act=list_edit">{$lang.open_captcha_config}</a>
    {/if}

  </td>
  <td>
  <input type="checkbox" name="captcha_register" value="1" {$captcha.register} />{$lang.captcha_register}<br />
  <input type="checkbox" name="captcha_login" value="2" {$captcha.login} />{$lang.captcha_login}<br />
  <input type="checkbox" name="captcha_comment" value="4"  {$captcha.comment} />{$lang.captcha_comment}<br />
  <input type="checkbox" name="captcha_admin" value="8" {$captcha.admin} />{$lang.captcha_admin}<br />
  <input type="checkbox" name="captcha_message" value="32" {$captcha.message} />{$lang.captcha_message}<br />
  </td>
</tr>
<tr>
  <td>
  <strong>{$lang.captcha_login_fail}</strong><br />
  {$lang.login_fail_note}
  </td>
  <td><input type="radio" name="captcha_login_fail" value="32" {$captcha.login_fail_yes} />{$lang.yes}<input type="radio"  name="captcha_login_fail" value="0" {$captcha.login_fail_no} />{$lang.no}</td>
</tr>
<tr>
  <td>
  <strong>{$lang.captcha_width}</strong><br />
  {$lang.width_note}
  </td>
  <td><input type="text" name="captcha_width" value="{$captcha_width}" /></td>
</tr>
<tr>
  <td>
  <strong>{$lang.captcha_height}</strong><br />
  {$lang.height_note}
  </td>
  <td><input type="text" name="captcha_height" value="{$captcha_height}" /></td>
</tr>
<tr>
  <td colspan="2" align="center"><input type="hidden" name="act" value="save_config" /><input type="submit" value="保存设置" class="button" /></td>
</tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js"}
{literal}
<script type="text/javascript" language="JavaScript">
<!--
onload = function() { startCheckOrder(); }

function validate()
{
  var width = document.forms["theForm"].elements["captcha_width"].value;
  var height = document.forms["theForm"].elements["captcha_height"].value;
  if(!Utils.isNumber(width))
  {
    alert(width_number);
    return false;
  }

  if(parseInt(width) > 145 || parseInt(width) < 40)
  {
    alert(proper_width);
    return false;
  }

  if(!Utils.isNumber(height))
  {
    alert(height_number);
    return false;
  }

  if(parseInt(height) > 50 || parseInt(height) < 15)
  {
    alert(proper_height);
    return false;
  }

  return true;
}

//屏蔽通过按钮

document.getElementById('codePassButton').hidden = true;
document.getElementById('captcha_machine_test_fail').hidden = true;

function onClickCode() {
  document.getElementById('codeVerifyTicket').value = '';
  document.getElementById('codeVerifyRandstr').value = '';
  var app_id = document.getElementById('codeVerifyAppid').value;

  //初始化验证码
  var captcha = new TencentCaptcha(app_id, function (res) {
    //判断是否验证成功

    if (res.ret == 0) {
      Ajax.call( 'captcha_manage.php?act=tencent_cpatcha_test', 'ticket=' + res.ticket + '&randstr=' + res.randstr, registed_callback , 'GET', 'TEXT', true, true );
      //将返回的ticket赋值给表单
      document.getElementById('codeVerifyTicket').value = res.ticket;
      document.getElementById('codeVerifyRandstr').value = res.randstr;
      //隐藏验证按钮
      document.getElementById('codeVerifyButton').type = 'hidden';
    }
  });

  function registed_callback(result)
  {
    if ( result == "true" )
    {
      //展示通过按钮
      document.getElementById('codePassButton').hidden = false;
      document.getElementById('codeVerifyFlag').value = 'ok';
    }
    else
    {
      //展示失败提示
      document.getElementById('captcha_machine_test_fail').hidden = false;
    }
  }

  //显示验证码
  captcha.show();

}
//-->
</script>
{/literal}
{insert_scripts files="../js/TCaptcha.js"}
{include file="pagefooter.htm"}
